home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_edit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  15.6 KB  |  538 lines

  1. /*****************************************************************************
  2.   FILE           : ui_edit.c
  3.   SHORTNAME      : edit.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : callbacks for editing sites and f-types
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 25.9.1990
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)ui_edit.c    1.10 3/2/94
  14.   SCCS VERSION   : 1.10
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include "ui.h"
  25.  
  26. #include <X11/Xaw/List.h>
  27.  
  28. #include "kr_ui.h"
  29.  
  30. #include "ui_infoP.h"  /* ui_info_displayList() */
  31. #include "ui_lists.h"
  32. #include "ui_xWidgets.h"
  33. #include "ui_confirmer.h"
  34. #include "ui_utilP.h"
  35. #include "ui_action.h"
  36.  
  37. #include "ui_edit.ph"
  38.  
  39.  
  40. /*****************************************************************************
  41.   FUNCTION : ui_edit_setCurrentSite
  42.  
  43.   PURPOSE  : makes this side current in the panel
  44.   RETURNS  : void
  45.   NOTES    :
  46.  
  47.   UPDATE   : 1.2.1990
  48. ******************************************************************************/
  49.  
  50. void ui_edit_setCurrentSite (char *name)
  51.  
  52. {
  53.     bool successful;
  54.     char *siteName, *func;
  55.  
  56.  
  57.     if (name != NULL) {
  58.     successful = krui_getFirstSiteTableEntry(&siteName, &func);
  59.     while (successful) {
  60.         if (strcmp(siteName,name) == 0) { /* site entry found */
  61.         sprintf(ui_edit_siteName, "%s", name);
  62.         ui_xSetString(ui_edit_siteNameWidget, ui_edit_siteName);
  63.         sprintf(ui_edit_siteFuncName, "%s", func);
  64.         ui_xSetLabel(ui_edit_siteFuncNameWidget, ui_edit_siteFuncName);
  65.         return;
  66.         } else 
  67.         successful = krui_getNextSiteTableEntry(&siteName, &func);
  68.     }
  69.     }
  70.     /* no such site was found or (name == NULL) */
  71.     ui_xSetString(ui_edit_siteNameWidget, "");
  72.     ui_xSetLabel(ui_edit_siteFuncNameWidget, "");
  73. }
  74.  
  75.  
  76. /*****************************************************************************
  77.   FUNCTION : ui_edit_selectFunction
  78.  
  79.   PURPOSE  : popup a list with all site functions
  80.   RETURNS  : void
  81.   NOTES    :
  82.  
  83.   UPDATE   : 1.2.1990
  84. ******************************************************************************/
  85.  
  86. void  ui_edit_selectFunction (Widget w, int type, caddr_t call_data)
  87.  
  88. {   
  89.     static struct SimpleListType listFunc;
  90.  
  91.     switch (type) {
  92.       case UI_EDIT_SITE_FUNC:
  93.     sprintf(listFunc.msg,"%s","Select site function:");
  94.     listFunc.unitPtr  = NULL;
  95.     listFunc.widgetPtr= w;
  96.     listFunc.listType = UI_LIST_SITE_FUNC;
  97.     ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
  98.     sprintf(ui_edit_siteFuncName,"%s",ui_list_returnName);
  99.     ui_xSetLabel(ui_edit_siteFuncNameWidget, ui_edit_siteFuncName);
  100.     break;
  101.       case UI_EDIT_ACT_FUNC:
  102.     sprintf(listFunc.msg,"%s","Select f-type activation function:");
  103.     listFunc.unitPtr  = NULL;
  104.     listFunc.widgetPtr= w;
  105.     listFunc.listType = UI_LIST_FTYPE_ACT_FUNC;
  106.     ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
  107.     sprintf(ui_edit_actFuncName,"%s",ui_list_returnName);
  108.     ui_xSetLabel(ui_edit_actFuncNameWidget, ui_edit_actFuncName);
  109.     break;
  110.       case UI_EDIT_OUT_FUNC:
  111.     sprintf(listFunc.msg,"%s","Select f-type output function:");
  112.     listFunc.unitPtr  = NULL;
  113.     listFunc.widgetPtr= w;
  114.     listFunc.listType = UI_LIST_FTYPE_OUT_FUNC;
  115.     ui_info_displayList(w, (struct SimpleListType *) &listFunc, NULL);
  116.     sprintf(ui_edit_outFuncName,"%s",ui_list_returnName);
  117.     ui_xSetLabel(ui_edit_outFuncNameWidget, ui_edit_outFuncName);
  118.     break;
  119.     }
  120. }
  121.  
  122.  
  123. /*****************************************************************************
  124.   FUNCTION : ui_edit_setSite
  125.  
  126.   PURPOSE  : change name and function of the current selected site
  127.   RETURNS  : void
  128.   NOTES    : This site is highlighted.
  129.              Callback from a SET-Button.
  130.  
  131.   UPDATE   : 20.9.90
  132. ******************************************************************************/
  133.  
  134. void  ui_edit_setSite(Widget w, struct SimpleListType *listDescriptorPtr, 
  135.     caddr_t call)
  136.  
  137. {
  138.     XawListReturnStruct  *listStructPtr;
  139.  
  140.     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
  141.     
  142.     if (listStructPtr->list_index == XAW_LIST_NONE) {
  143.     ui_confirmOk("No site in the site list selected!");
  144.     return;
  145.     }
  146.  
  147.     ui_xStringFromAsciiWidget(ui_edit_siteNameWidget, ui_edit_siteName, 
  148.                   MAX_NAME_LENGTH);
  149.     ui_correctName(ui_edit_siteName);
  150.     ui_checkError(krui_changeSiteTableEntry(listStructPtr->string,
  151.                         ui_edit_siteName,
  152.                         ui_edit_siteFuncName));
  153.     if (ui_kernelError < 0)
  154.     ui_confirmOk("Name or function invalid!");
  155.     else {
  156.     free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
  157.     (listDescriptorPtr->listPtr)[listStructPtr->list_index] =
  158.         XtNewString(ui_edit_siteName);
  159.     XawListChange(listDescriptorPtr->listWidget, 
  160.               listDescriptorPtr->listPtr, 
  161.               listDescriptorPtr->noOfItems, 0, True);
  162.     }
  163. }
  164.  
  165.  
  166. /*****************************************************************************
  167.   FUNCTION : ui_edit_listSetSite
  168.  
  169.   PURPOSE  : callback. Called when a site in the site list was seleted.
  170.   RETURNS  : void
  171.   NOTES    :
  172.  
  173.   UPDATE   : 28.8.1990
  174. ******************************************************************************/
  175.  
  176. void ui_edit_listSetSite (Widget w, int editType, 
  177.     XawListReturnStruct *listStructPtr) /* call_data of list widgets */
  178.  
  179. {
  180.     switch (editType) {
  181.       case UI_EDIT_FTYPE:
  182.     break;
  183.       case UI_EDIT_SITE:
  184.     ui_edit_setCurrentSite(listStructPtr->string);
  185.     break;
  186.     }
  187. }
  188.  
  189.  
  190. /*****************************************************************************
  191.   FUNCTION : ui_edit_newSite
  192.  
  193.   PURPOSE  : callback. Called when the creation of a new site was requested.
  194.   RETURNS  : void
  195.   NOTES    :
  196.  
  197.   UPDATE   : 1.2.1990
  198. ******************************************************************************/
  199.  
  200. void  ui_edit_newSite (Widget w, struct SimpleListType *listDescriptorPtr, 
  201.      caddr_t call)
  202.  
  203. {
  204.     ui_xStringFromAsciiWidget(ui_edit_siteNameWidget, ui_edit_siteName, 
  205.                   MAX_NAME_LENGTH);
  206.     ui_correctName(ui_edit_siteName);
  207.     if ((strlen(ui_edit_siteName) == 0) OR (strlen(ui_edit_siteFuncName) == 0)) {
  208.     ui_confirmOk("Invalid name or function!");
  209.     return;
  210.     }
  211.  
  212.     ui_checkError(krui_createSiteTableEntry(ui_edit_siteName, 
  213.                         ui_edit_siteFuncName));
  214.     if (ui_kernelError >= 0) {
  215.     if (ui_list_noOfSites++ == 0) {
  216.         /* first entry is "*** no sites ***" */
  217.         free((listDescriptorPtr->listPtr)[0]);
  218.         (listDescriptorPtr->listPtr)[0] = 
  219.         XtNewString(ui_edit_siteName);
  220.     } else
  221.         ui_xAddListEntry(listDescriptorPtr, ui_edit_siteName);
  222.     XawListChange(listDescriptorPtr->listWidget, listDescriptorPtr->listPtr, 
  223.               listDescriptorPtr->noOfItems, 0, True);
  224.     }
  225. }
  226.  
  227.  
  228. /*****************************************************************************
  229.   FUNCTION : ui_edit_deleteSite
  230.  
  231.   PURPOSE  : callback. Called when a site should be deleted 
  232.   RETURNS  : void
  233.   NOTES    :
  234.  
  235.   UPDATE   : 1.2.1990
  236. ******************************************************************************/
  237.  
  238. void  ui_edit_deleteSite (Widget w, struct SimpleListType *listDescriptorPtr, 
  239.      caddr_t call)
  240.  
  241. {
  242.     XawListReturnStruct   *listStructPtr;
  243.     int                   i;
  244.  
  245.     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
  246.  
  247.     if ((listStructPtr->list_index == XAW_LIST_NONE) OR
  248.     (ui_list_noOfSites <= 0))
  249.     return; /* no site selected */
  250.  
  251.     ui_checkError(krui_deleteSiteTableEntry(listStructPtr->string));
  252.     
  253.     /* remove this entry from the array */
  254.     free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
  255.     for (i = listStructPtr->list_index + 1; 
  256.      i <= listDescriptorPtr->noOfItems - 1; i++)
  257.     (listDescriptorPtr->listPtr)[i-1] = (listDescriptorPtr->listPtr)[i];
  258.     if (ui_list_noOfSites-- == 1) { /* last site deleted */
  259.     (listDescriptorPtr->listPtr)[0] = XtNewString("*** no sites");
  260.     XawListChange(listDescriptorPtr->listWidget, 
  261.           listDescriptorPtr->listPtr, 
  262.           1, 0, True);
  263.     } else
  264.     XawListChange(listDescriptorPtr->listWidget, 
  265.               listDescriptorPtr->listPtr, 
  266.               --listDescriptorPtr->noOfItems, 0, True);
  267. }
  268.  
  269.  
  270. /*****************************************************************************
  271.   FUNCTION : ui_edit_displayFType
  272.  
  273.   PURPOSE  : display given ftype 
  274.   RETURNS  : void
  275.   NOTES    :
  276.  
  277.   UPDATE   : 20.9.1990
  278. ******************************************************************************/
  279.  
  280. static void  ui_edit_displayFType(char *name, 
  281.     struct SimpleListType *listDescriptorPtr)
  282.  
  283. {
  284.     if (krui_setFTypeEntry(name)) {
  285.     sprintf(ui_edit_ftypeName,   "%s", krui_getFTypeName());
  286.     sprintf(ui_edit_actFuncName, "%s", krui_getFTypeActFuncName());
  287.     sprintf(ui_edit_outFuncName, "%s", krui_getFTypeOutFuncName());
  288.     ui_list_buildList(listDescriptorPtr);
  289.  
  290.     ui_xSetString(ui_edit_ftypeNameWidget , ui_edit_ftypeName);
  291.     ui_xSetLabel(ui_edit_actFuncNameWidget, ui_edit_actFuncName);
  292.     ui_xSetLabel(ui_edit_outFuncNameWidget, ui_edit_outFuncName);
  293.  
  294.     XawListChange(listDescriptorPtr->listWidget, 
  295.               listDescriptorPtr->listPtr,     
  296.               listDescriptorPtr->noOfItems, 0, True);
  297.     } else {
  298.     ui_xSetString(ui_edit_ftypeNameWidget , "");
  299.     ui_xSetLabel(ui_edit_actFuncNameWidget, "");
  300.     ui_xSetLabel(ui_edit_outFuncNameWidget, "");
  301.     
  302.     listDescriptorPtr->noOfItems = 0;
  303.     ui_xAddListEntry(listDescriptorPtr, "*** no sites ***");
  304.     ui_list_noOfSites = 0;
  305.     XawListChange(listDescriptorPtr->listWidget, 
  306.               listDescriptorPtr->listPtr,     
  307.               listDescriptorPtr->noOfItems, 0, True);
  308.     }
  309. }
  310.  
  311.  
  312. /*****************************************************************************
  313.   FUNCTION : ui_edit_displayFirstFType
  314.  
  315.   PURPOSE  : display first ftype 
  316.   RETURNS  : void
  317.   NOTES    :
  318.  
  319.   UPDATE   : 20.9.1990
  320. ******************************************************************************/
  321.  
  322. void  ui_edit_displayFirstFType (struct SimpleListType *listDescriptorPtr)
  323.  
  324. {
  325.     if (krui_setFirstFTypeEntry()) {
  326.     sprintf(ui_edit_ftypeName,   "%s", krui_getFTypeName());
  327.     ui_edit_displayFType(ui_edit_ftypeName, listDescriptorPtr);
  328.     }
  329. }
  330.  
  331.  
  332. /*****************************************************************************
  333.   FUNCTION : ui_edit_ftypeAddSite
  334.  
  335.   PURPOSE  : popup site list
  336.              if a site was choosen add it to the list
  337.   RETURNS  : void
  338.   NOTES    :
  339.  
  340.   UPDATE   : 20.9.1990
  341. ******************************************************************************/
  342.  
  343. void  ui_edit_ftypeAddSite (Widget w, 
  344.     struct SimpleListType *listDescriptorPtr, caddr_t call)
  345.  
  346.     static struct SimpleListType listSites;
  347.  
  348.     sprintf(listSites.msg,"%s","Select site to add:");
  349.     listSites.unitPtr  = NULL;
  350.     listSites.widgetPtr= w;
  351.     listSites.listType = UI_LIST_SITE;
  352.     ui_info_displayList(w, (struct SimpleListType *) &listSites, NULL);
  353.     if (ui_list_returnIndex != XAW_LIST_NONE) {
  354.     if (ui_list_noOfFTypeSites++ == 0) {
  355.         /* first entry is "*** no sites ***" */
  356.         /* replace the first dummy entry     */
  357.         free((listDescriptorPtr->listPtr)[0]);
  358.         (listDescriptorPtr->listPtr)[0] = 
  359.         XtNewString(ui_list_returnName);
  360.     } else
  361.         ui_xAddListEntry(listDescriptorPtr, ui_list_returnName);
  362.     XawListChange(listDescriptorPtr->listWidget, listDescriptorPtr->listPtr, 
  363.               listDescriptorPtr->noOfItems, 0, True);
  364.     }
  365. }
  366.  
  367.  
  368. /*****************************************************************************
  369.   FUNCTION : ui_edit_ftypeDeleteSite
  370.  
  371.   PURPOSE  : remove highlighted site from list
  372.   RETURNS  : void
  373.   NOTES    :
  374.  
  375.   UPDATE   : 20.9.1990
  376. ******************************************************************************/
  377.  
  378. void  ui_edit_ftypeDeleteSite (Widget w, 
  379.     struct SimpleListType *listDescriptorPtr, caddr_t call)
  380.  
  381. {
  382.     XawListReturnStruct   *listStructPtr;
  383.     int                   i;
  384.  
  385.     listStructPtr = XawListShowCurrent(listDescriptorPtr->listWidget);
  386.  
  387.     if ((listStructPtr->list_index == XAW_LIST_NONE) OR
  388.     (ui_list_noOfFTypeSites <= 0))
  389.     return; /* no site selected */
  390.  
  391.     /* remove this entry from the array */
  392.     free((listDescriptorPtr->listPtr)[listStructPtr->list_index]);
  393.     for (i = listStructPtr->list_index + 1; 
  394.      i <= listDescriptorPtr->noOfItems - 1; i++)
  395.     (listDescriptorPtr->listPtr)[i-1] = (listDescriptorPtr->listPtr)[i];
  396.     if (ui_list_noOfFTypeSites-- == 1) { /* last site deleted */
  397.     (listDescriptorPtr->listPtr)[0] = XtNewString("*** no sites");
  398.     XawListChange(listDescriptorPtr->listWidget, 
  399.           listDescriptorPtr->listPtr, 
  400.           1, 0, True);
  401.     } else
  402.     XawListChange(listDescriptorPtr->listWidget, 
  403.               listDescriptorPtr->listPtr, 
  404.               --listDescriptorPtr->noOfItems, 0, True);
  405. }
  406.  
  407.  
  408. /*****************************************************************************
  409.   FUNCTION : ui_edit_chooseFType
  410.  
  411.   PURPOSE  : display a list of all existingf f-types
  412.   RETURNS  : void
  413.   NOTES    :
  414.  
  415.   UPDATE   : 20.9.1990
  416. ******************************************************************************/
  417.  
  418. void  ui_edit_chooseFType (Widget  w, 
  419.      struct SimpleListType *listDescriptorPtr, caddr_t call)
  420.  
  421. {
  422.     static struct SimpleListType listFTypes;
  423.  
  424.     if (krui_setFirstFTypeEntry()) {
  425.     sprintf(listFTypes.msg,"%s","Choose f-type to edit:");
  426.     listFTypes.unitPtr  = NULL;
  427.     listFTypes.widgetPtr= w;
  428.     listFTypes.listType = UI_LIST_FTYPE_NAME;
  429.     ui_info_displayList(w, (struct SimpleListType *) &listFTypes, NULL);
  430.     sprintf(ui_edit_ftypeName,"%s", ui_list_returnName);
  431.     ui_edit_displayFType(ui_edit_ftypeName, listDescriptorPtr);
  432.     }
  433. }
  434.  
  435.  
  436. /*****************************************************************************
  437.   FUNCTION : ui_edit_setFType
  438.  
  439.   PURPOSE  : update ftype name and functions; sites remain unchanged
  440.   RETURNS  : void
  441.   NOTES    :
  442.  
  443.   UPDATE   : 20.9.1990
  444. ******************************************************************************/
  445.  
  446. void  ui_edit_setFType (Widget w, 
  447.      struct SimpleListType *listDescriptorPtr, caddr_t call)
  448.  
  449. {
  450.     char buf[MAX_NAME_LENGTH];
  451.  
  452.     if (NOT krui_setFTypeEntry(ui_edit_ftypeName)) {
  453.     sprintf(buf,"Invalid f-type: %s", ui_edit_ftypeName);
  454.     ui_confirmOk(buf);
  455.     return;
  456.     }
  457.  
  458.     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, buf, 
  459.                   MAX_NAME_LENGTH);
  460.     ui_correctName(buf);
  461.     if (strcmp(buf,ui_edit_ftypeName) != 0) {
  462.     strcpy(ui_edit_ftypeName, buf);
  463.     ui_checkError(krui_setFTypeName(ui_edit_ftypeName));
  464.     }
  465.     ui_checkError(krui_setFTypeActFunc(ui_edit_actFuncName));
  466.     ui_checkError(krui_setFTypeOutFunc(ui_edit_outFuncName));
  467. }
  468.  
  469.  
  470. /*****************************************************************************
  471.   FUNCTION : ui_edit_newFType
  472.  
  473.   PURPOSE  : create a new f-type
  474.   RETURNS  : void
  475.   NOTES    :
  476.  
  477.   UPDATE   : 20.9.1990
  478. ******************************************************************************/
  479.  
  480. void  ui_edit_newFType (Widget w, 
  481.      struct SimpleListType *listDescriptorPtr, caddr_t call)
  482.  
  483. {
  484.     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, ui_edit_ftypeName,
  485.                   MAX_NAME_LENGTH);
  486.     ui_correctName(ui_edit_ftypeName);
  487.  
  488.     if (strlen(ui_edit_ftypeName) > 0) {
  489.     ui_checkError(krui_createFTypeEntry(ui_edit_ftypeName,
  490.                         ui_edit_actFuncName,
  491.                         ui_edit_outFuncName,
  492.                         ui_list_noOfFTypeSites,
  493.                         listDescriptorPtr->listPtr));
  494.     if (ui_kernelError < 0)
  495.         ui_confirmOk("Creation of this f-type failed!");
  496.     } else
  497.     ui_confirmOk("No f-type name given!");
  498. }
  499.  
  500.  
  501. /*****************************************************************************
  502.   FUNCTION : ui_edit_deleteFType
  503.  
  504.   PURPOSE  : delete f-type with the given name 
  505.   RETURNS  : void
  506.   NOTES    :
  507.  
  508.   UPDATE   : 20.9.1990
  509. ******************************************************************************/
  510.  
  511. void  ui_edit_deleteFType(Widget w, 
  512.      struct SimpleListType *listDescriptorPtr, caddr_t call)
  513.  
  514. {
  515.     ui_xStringFromAsciiWidget(ui_edit_ftypeNameWidget, ui_edit_ftypeName,
  516.                   MAX_NAME_LENGTH);
  517.     ui_correctName(ui_edit_ftypeName);
  518.     ui_checkError(krui_deleteFTypeEntry(ui_edit_ftypeName));
  519.     if (ui_kernelError < 0) {
  520.     char buf[MAX_NAME_LENGTH];
  521.     sprintf(buf,"Can't delete f-type: %s",ui_edit_ftypeName);
  522.     ui_confirmOk(buf);
  523.     } else
  524.     ui_edit_displayFirstFType(listDescriptorPtr);
  525. }
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535. /* end of file */
  536. /* lines: 570 */
  537.